<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="详情" :footer="null" width="60%" destroyOnClose>
    <Description :column="1" :data="dataInfo" :schema="formSchema" />
    <a-descriptions style="margin-top: 20px;" title="检测结果" :column="1" bordered>
        <a-descriptions-item label="报告时间">{{reportInfo.reportDate}}</a-descriptions-item>
        <a-descriptions-item label="检测报告">
          <a-button style="margin-right: 5px;" :ghost="true" v-for="item in reportInfo.report" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(item)">下载</a-button>
        </a-descriptions-item>
    </a-descriptions>
  </BasicModal>
</template>
<script lang="ts" setup>
import { ref, useAttrs } from 'vue';
import { Description, useDescription } from '/@/components/Description/index';
import BasicModal from "/@/components/Modal/src/BasicModal.vue";
import {useModalInner} from "/@/components/Modal";
import {getOne} from '../../TInspection/TInspection.api';
import { downloadFile } from '/@/utils/common/renderUtils';
const emit = defineEmits(['register']);
const attrs = useAttrs();
const dataInfo = ref({});
const  formSchema =   [
  {
    label: '检测编号',
    field: 'submissionNo',
  },
  {
    label: '检测类型',
    field: 'type',
    render: (curVal, data) => {
      return curVal == 1 ? '品质' : '土壤';
    },
  },
  {
    label: '样品名称',
    field: 'bizName',
  },
  {
    label: '样品量',
    field: 'sampleSize',
    render: (curVal, data) => {
      return curVal ? curVal+'kg' : '';
    },
  },
  {
    label: '主要检测指标及要求',
    field: 'sampleDescription',
  },
  {
    label: '送检日期',
    field: 'submitDate',
  },
  {
    label: '送检人',
    field: 'submitter',
  },
  {
    label: '联系方式',
    field: 'submitterContact',
  },
  {
    label: '送检状态',
    field: 'statusDictText',
  },
  {
    label: '检测机构',
    field: 'testOrgId_dictText',
  }
]
const reportInfo = ref({});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  setModalProps({ confirmLoading: false });
  console.log(data);
  dataInfo.value = data.record;
  console.log(dataInfo.value);
  reportInfo.value = {}
  if (data.record.inspectionId) {
    getOne({id: data.record.inspectionId}).then(res => {
      console.log(res)
      res.report = res.report ? res.report.split(',') : []
      reportInfo.value = res
    })
  }
});
</script>

<style>
  .ant-descriptions-item-label {
    width: 200px;
  }
</style>
